package com.example.zhongshuishi.controller;

import com.example.zhongshuishi.entity.PersonnelDto;
import com.example.zhongshuishi.service.PersonnelService;
import jakarta.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author 鑫程垬纾
 * @version 1.0
 * @description TODO
 * @date 2025/3/29 12:27
 */
@RestController
@RequestMapping("/api/personal")
public class PersonalController {
    Logger logger = LoggerFactory.getLogger(PersonalController.class);

    @Autowired
    private PersonnelService personnelService;

    //查询当前用户下的所有代理人
    @GetMapping("/list")
    public List<PersonnelDto> getPersonalList(@NotNull Integer parentId) {
        try{
            logger.info("/personal/list getPersonalList start");
            List<PersonnelDto> personnelDtos = personnelService.selectByParentId(parentId);
            return personnelDtos;
        }catch (Exception e ){
            e.printStackTrace();
            logger.error("/personal/list getPersonalList error ="+e.getMessage());
        }
        return null;
    }


    //查询当前用户下的所有代理人
    @GetMapping("/getPersonalByPhone")
    public PersonnelDto getPersonalByPhone(@NotNull String phone) {
        try{
            logger.info("/getPersonalByPhone getPersonalList start");
            PersonnelDto personnelDto = personnelService.selectByPhone(phone);
            return personnelDto;
        }catch (Exception e ){
            e.printStackTrace();
            logger.error("/getPersonalByPhone error ="+e.getMessage());
        }
        return null;
    }
}


